package bkq.viettravel.bll;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import bkq.viettravel.database.SqliteServices;
import bkq.viettravel.dto.ImageDTO;
import bkq.viettravel.interf.IObjectCommon;

public class ImageBLL implements IObjectCommon<ImageDTO>{
	
	SqliteServices service = null;
	
	public ImageBLL(Context context) {
		service = new SqliteServices(context);
	}

	@Override
	public ArrayList<ImageDTO> getAll(String sql) {
		ArrayList<ImageDTO> tmp = new ArrayList<ImageDTO>();
		ImageDTO image = null;
		Cursor c = service.queryData(sql);
		try {
			if(c.moveToFirst())
			{
				do
				{
					image = new ImageDTO();
					image.setId(Integer.parseInt(c.getString(c.getColumnIndex("id"))));
					image.setLinkImage(c.getString(c.getColumnIndex("link")));
					image.setIdTravel(Integer.parseInt(c.getString(c.getColumnIndex("idTravel"))));
					tmp.add(image);
				}
				while(c.moveToNext());
				c.close();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return tmp.size() == 0? null : tmp;
	}

	@Override
	public ArrayList<ImageDTO> getAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean insert(ImageDTO obj) {
		// TODO Auto-generated method stub
		return false;
	}
	
	public ArrayList<ImageDTO> getByIdTravel(int idTravel)
	{
		String sql = "select * from Image where idTravel = "+idTravel+"";
		ArrayList<ImageDTO> tmp = getAll(sql);
		return tmp.size() == 0  ? null : tmp;
	}

}
